package com.his.registration.controller;

import com.his.common.Result;
import com.his.registration.service.PrescriptionService;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * @BelongsProject: workspace-idea
 * @BelongsPackage: com.his.registration.controller
 * @Author: ZhangYing
 * @Date: 2023/7/7 9:21
 * @Description:
 */
@RestController
@CrossOrigin
@RequestMapping("/prescription")
public class PrescriptionController {
    @Autowired
    private PrescriptionService prescriptionService;

    @RequestMapping("/insert")
    public Result insert(int registerId, int drugId) {
        String drugState="已开立";
        LocalDateTime creationTime=LocalDateTime.now();
        int result = prescriptionService.insert(registerId, drugId, creationTime, drugState);
        //获得插入的id
        int insertId = prescriptionService.getInsertId();
        return Result.success(insertId);
    }

    //数据更新
    @RequestMapping("/update")
    public Result update(String drugUsage,int drugNumber,int id){
        int result = prescriptionService.update(drugUsage, drugNumber, id);
        return Result.success("成功更新"+result+"条处方数据");
    }

    //根据id删除处方
    @RequestMapping("/deleteById")
    public Result deleteById(int id){
        int result = prescriptionService.deleteById(id);
        return Result.success("成功删除"+result+"处方");
    }
}
